<template>
    <div class="cmt-container">
        <h3>发表评论</h3>
        <hr>
        <textarea placeholder="请随便BB（最多120字）" maxlength="120" v-model="conent"></textarea>
        <mt-button type="primary" size="large" @click="add">发表评论</mt-button>
        <div class="cmt-list">
            <div class="cmt-item" v-for="(item,i) in newsinfo" :key="i">
                <div class="cmt-title">
                    第{{ i+1 }}楼&nbsp;&nbsp;用户:{{item.user_name}}&nbsp;&nbsp;发表时间:{{item.add_time | dateFormat}}
                </div>
                <div class="cmt-body">
                    {{ item.conent }}
                </div>
            </div>
        </div>        
        <!-- <mt-button type="danger" size="large" plain>加载更多</mt-button> -->
    </div>
</template>

<script>
import { Toast } from "mint-ui"
export default {
    data(){
        return{
            conent:'',
            newsinfo:[
               {user_name:'匿名用户',add_time:'2020-12-12 12:12:12',conent:'好累哦'},
               {user_name:'匿名用户',add_time:'2020-12-12 12:12:13',conent:'好累13'},
               {user_name:'匿名用户',add_time:new Date(),conent:'好累1321'}
            ]
        }
    },
    methods:{
        add(){ // 添加评论
            if(this.conent !== '')
            {
                var newlist={user_name:'匿名用户',add_time:new Date(),conent:this.conent}
                this.newsinfo.unshift(newlist)
                this.conent=''
            }else{
                Toast('请输入评论!');
            }            
        }
        // getComments(){
        //     this.$http.get('api').then(result =>{
        //         if(result.body.status === 0){
        //             // 成功
        //         }else{
        //             // 失败
        //         }
        //     })
        // }        
    }
    
}
</script>


<style lang="scss" scoped>
.cmt-container{
    h3{
        font-size: 18px;
    }
    textarea{
        font-size: 14px;
        height: 85px;
        margin: 0;
    }
    .cmt-list{
        margin: 6px 0;
        .cmt-item{
            font-size: 13px;
            .cmt-title{
                line-height: 30px;
                background-color: #ccc;
            }
            .cmt-body{
                line-height: 35px;
                text-indent: 2em;
            }
        }
    }
}
</style>